/**
 * axios请求拦截器
 */
import request from '../util/request'
import { HttpStatusCode, getHttpStatusMessage } from 'declares/constant/http-status-code'
import { HttpResponseData } from '@/declare/http-response-data';
import { ServiceStatusCode } from '@/declare/constant/service-status-code';

// 请求拦截器
request.interceptors.request.use((config) => {
    
    return config;
}, (error) => {
    return Promise.reject(error);
});



// 响应拦截器
request.interceptors.response.use((response) => {
    if(response.status != HttpStatusCode.OK) {
        // 请求未成功返回
        return Promise.reject(getHttpStatusMessage(response));
    }

    const result: HttpResponseData = response.data;
    if(result.code == ServiceStatusCode.OK) {
        // 请求成功
        return result.data;
    }
    
    // 对响应错误进行处理

    return response;
}, (error) => {

    return Promise.reject(error);
});